﻿using System;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[RequireComponent(typeof(InputField))]
public class UISliderValueInputField : MonoBehaviour
{
    private InputField inputField;
    public Slider slider;

    private void Start()
    {
        this.inputField = base.GetComponent<InputField>();
        if (this.slider != null)
        {
            this.inputField.text = this.slider.value + string.Empty;
            this.slider.onValueChanged.AddListener((UnityAction<float>) (v => (this.inputField.text = v + string.Empty)));
        }
        this.inputField.onEndEdit.AddListener(delegate (string v) {
            if (this.slider != null)
            {
                int result = 0;
                int.TryParse(v, out result);
                this.slider.value = result;
            }
        });
    }
}

